package com.ruoyi.web.controller.race;

import java.util.Arrays;
import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.live.base.domain.LiveScoreStandard;
import com.ruoyi.live.base.service.ILiveScoreStandardService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 评分标准Controller
 *
 * @author ruoyi
 * @date 2023-01-29
 */
@RestController
@RequestMapping("/race/standard")
public class LiveScoreStandardController extends BaseController
{
    @Autowired
    private ILiveScoreStandardService liveScoreStandardService;

    /**
     * 查询评分标准列表
     */
    @PreAuthorize("@ss.hasPermi('race:standard:list')")
    @GetMapping("/list")
    public AjaxResult list(LiveScoreStandard liveScoreStandard)
    {
        List<LiveScoreStandard> list = liveScoreStandardService.selectLiveScoreStandardList(liveScoreStandard);
        return success(list);
    }

    /**
     * 导出评分标准列表
     */
    @PreAuthorize("@ss.hasPermi('race:standard:export')")
    @Log(title = "评分标准", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LiveScoreStandard liveScoreStandard)
    {
        List<LiveScoreStandard> list = liveScoreStandardService.selectLiveScoreStandardList(liveScoreStandard);
        ExcelUtil<LiveScoreStandard> util = new ExcelUtil<LiveScoreStandard>(LiveScoreStandard.class);
        util.exportExcel(response, list, "评分标准数据");
    }

    /**
     * 获取评分标准详细信息
     */
    @PreAuthorize("@ss.hasPermi('race:standard:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(liveScoreStandardService.getById(id));
    }

    /**
     * 新增评分标准
     */
    @PreAuthorize("@ss.hasPermi('race:standard:add')")
    @Log(title = "评分标准", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LiveScoreStandard liveScoreStandard)
    {
        liveScoreStandard.setState(1);
        return toAjax(liveScoreStandardService.save(liveScoreStandard));
    }

    /**
     * 修改评分标准
     */
    @PreAuthorize("@ss.hasPermi('race:standard:edit')")
    @Log(title = "评分标准", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LiveScoreStandard liveScoreStandard)
    {
        return toAjax(liveScoreStandardService.saveOrUpdate(liveScoreStandard));
    }

    /**
     * 删除评分标准
     */
    @PreAuthorize("@ss.hasPermi('race:standard:remove')")
    @Log(title = "评分标准", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        List<Long> list = Arrays.asList(ids);
        return toAjax(liveScoreStandardService.removeByIds(list));
    }
}
